import {Component, Input} from '@angular/core';
import {DomSanitizer} from "@angular/platform-browser";
import {AlertController, ToastController,App} from "ionic-angular";
import {JidihttpProvider} from "../../providers/jidihttp/jidihttp";
import {BozhuinfoPage} from "../../pages/bozhuinfo/bozhuinfo";
/**
 * Generated class for the HuifulistComponent component.
 *
 * See https://angular.io/api/core/Component for more info on Angular
 * Components.
 */
@Component({
  selector: 'huifulist',
  templateUrl: 'huifulist.html'
})
export class HuifulistComponent {
  logintype:string;
  @Input() leizhuhuifu:any;
  @Input() listitemhuifu:any;
  constructor(public sanitizer:DomSanitizer,private app:App,public alertCtrl: AlertController,public jidiProvider:JidihttpProvider,public toastCtrl: ToastController) {

  }


  assembleHTML(strHTML:any){
    return this.sanitizer.bypassSecurityTrustHtml(strHTML);
  }

  toLeizhu(uid:string){
    this.app.getRootNav().push(BozhuinfoPage,{uuid:uid});

  }
  /** 回复 **/
  doPrompt(idd:string,parentidd:string,aa:string,bb:string) {
    this.logintype =localStorage.getItem('login');
    if("no"==this.logintype){
      this.showToast("请登陆后操作！");
    }else {
      let prompt = this.alertCtrl.create({
        title: '',
        message: "请输入内容",
        inputs: [
          {
            name: 'title',
            placeholder: '请输入'
          },
        ],
        buttons: [
          {
            text: '取消',
            handler: data => {
              console.log('Cancel clicked');
            }
          },
          {
            text: '确定',
            handler: data => {
              this.huifuHttp(idd, parentidd, data.title, aa, bb);
            }
          }
        ]
      });
      prompt.present();
    }
  }

  /** http click**/
  huifuHttp(a:string,b:string,c:string,aa:string,bb:string){
    this.jidiProvider.huiFuMessage(a,b,c,aa,bb).subscribe(data => {
      if(data['success']){
        this.showToast(data['message']);
      }else{
        this.showToast(data['message']);
      }



    },error => {
      this.showToast("error");
    });
  }
  /** 提示信息 **/
  showToast(position: string) {
    let toast = this.toastCtrl.create({
      message: position,
      duration: 2000,
      position: "middle"
    });

    toast.present(toast);
  }
}
